/**
 * 
 */
package qualification2010;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * @author Coddy created on 2010-5-8
 * 
 */
public class ThemePark
{

	static String currentInput = "C-large.in";
	static String currentOutput = "C-large.out";

	public static void main(String[] args)
	{

		try
		{
			BufferedReader bf = new BufferedReader(new FileReader(currentInput));
			BufferedWriter bw = new BufferedWriter(
					new FileWriter(currentOutput));
			int t = Integer.parseInt(bf.readLine());
			for (int testcase = 0; testcase < t; testcase++)
			{
				String line = bf.readLine();

				StringTokenizer tokenizer = new StringTokenizer(line);
				int r = 0, k = 0, n = 0;
				if (tokenizer.hasMoreElements())
				{
					r = Integer.parseInt((String) tokenizer.nextElement());
					k = Integer.parseInt((String) tokenizer.nextElement());
					n = Integer.parseInt((String) tokenizer.nextElement());
				}

				line = bf.readLine();
				tokenizer = new StringTokenizer(line);
				int count = 0;
				int total = 0;
				int[] groups = new int[n];
				while (tokenizer.hasMoreElements())
				{
					String string = (String) tokenizer.nextElement();
					groups[count] = Integer.parseInt(string);
					total += groups[count];
					count++;
				}

				// HANDLE
				int people = 0;
				int money = 0;
				int index = 0;
				for (int i = 0; i < r; i++)
				{
					while (people + groups[index] <= k && people < total)
					{
						money += groups[index % n];
						people += groups[index % n];
						index++;
						index = index % n;
					}
					people = 0;
				}
				bw.write("Case #" + (testcase + 1) + ": " + money);
				bw.write("\n");
			}
			bw.flush();
			System.out.println("finishe");
		} catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
